<template>
  <div>
    <MyHeader fontColor="white" bgColor="#78bb7b" title="购物车" />
    <div class="list" style="padding: 45px 0 50px">
      <MyGoods v-for="obj in list" :key="obj.id" :goodsObj="obj" />
    </div>
    <MyFooter :goodsArr="list" @toggleAll="toggleAllPar" :isAllChecked="isAllSelected"/>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader.vue";
import MyGoods from "./components/MyGoods.vue";
import MyFooter from "./components/MyFooter.vue";
export default {
  data() {
    return {
      list: [], //商品所有数据
    };
  },
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  async created() {
    // 不必在自己引入axios变量, 而是直接使用全局属性$axios
    let resp = await this.$http({
      method: "get",
      url: "/api/cart",
    });
    // console.log(resp.data);
    this.list = resp.data.list;
  },
  methods:{
      toggleAllPar(checked){
        //   console.log(checked);
        this.list.forEach(item=>item.goods_state=checked)
      }
  },
  computed:{
      isAllSelected(){
        return  this.list.every(item=>item.goods_state)
      }
  },
};
</script>

<style>
</style>